package Persons;

our $ISA = qw/Person/;
sub new{
	my $class = shift;
	my $self = {
		firstName => shift,
		lastName => shift,
		cpr => shift,
		gender => shift,
	};
	unless($self->{cpr} =~ /\d\d\d\d\d\d\-\d\d/){
		print "Wrong cpr!\n";
		return undef;
	}
	unless($self->{gender} =~ /male/i || $self->{gender} =~ /female/i){
		print "Gender must be either male or female\n";
		return undef;
	}
	bless $self, $class;
	$self->birthday();
	return $self;
}

sub birthday{
	$self->{birthday} = `date`;
	print "my birthday is $self->{birthday}";
}

sub first_name{
	$self = shift;
	if(@_){$self->{firstName} = shift;}
	print "First name : " . $self->{firstName} . "\n";
} 
sub last_name{
	$self = shift;
	if(@_){$self->{lastName} = shift;}
	print "Last name = $self->{lastName}\n";
}

sub cpr{
	$self = shift;
	if(@_){$self->{cpr} = shift;}
	print "cpr = $self->{cpr}\n";
}

sub gender{
	$self = shift;
	if(@_){$self->{gender} = shift;}
	print "Gender = $self->{gender}\n";
}
sub toString{
	$self = shift;
	$self->first_name();
	$self->last_name();
	$self->cpr();
	$self->gender();
}
sub equals(){
	$self = shift;
	$p2 = shift;
	if($self->{firstName} == $p2->{firstName} &&
	   $self->{lastName} == $p2->{lastName} &&
	   $self->{cpr} == $p2->{cpr} &&
	   $self->{gender} == $p2->{gender}){
		return 1;
	}
	return undef;
}
1;
